﻿namespace LeadMaster.Controllers
{
  using System;
  using System.Linq;
  using System.Web.Mvc;
  using LeadMaster.DAL;
  using LeadMaster.ViewModels;
  using System.Web.Security;
  using LeadMaster.Helpers;
  using System.Collections.Generic;
  using LeadMaster.Models;
  using System.Data;
  using LeadMaster.Properties;
  using System.Configuration;
  using System.Data.Entity;
  using System.Data.Entity.Core.Objects;
  using PagedList;

    public class FinanceTypesController : Controller
    {

      private DunsmoreContext db = new DunsmoreContext();

        public ActionResult Index()
        {
            return View(db.FinanceTypes.ToList());
        }

        //
        // GET: /FinanceTypes/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /FinanceTypes/Create

        public ActionResult Create()
        {
          FinanceTypes ft = new FinanceTypes();
            return View(ft);
        }

        //
        // POST: /FinanceTypes/Create

        [HttpPost]
        public ActionResult Create(FinanceTypes ft)
        {
            try
            {
              db.FinanceTypes.Add(ft);
              db.SaveChanges();

              return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /FinanceTypes/Edit/5

        public ActionResult Edit(int id)
        {
            FinanceTypes ft = db.FinanceTypes.Find(id);
            return View(ft);
        }

        //
        // POST: /FinanceTypes/Edit/5

        [HttpPost]
        public ActionResult Edit(FinanceTypes ft)
        {
            try
            {
              db.Entry(ft).State = EntityState.Modified;
              db.SaveChanges();

              return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /FinanceTypes/Delete/5

        public ActionResult Delete(int id)
        {
            FinanceTypes ft = db.FinanceTypes.Find(id);
            return View(ft);
        }

        //
        // POST: /FinanceTypes/Delete/5

        [HttpPost]
        public ActionResult Delete(FinanceTypes ft)
        {
            try
            {
              FinanceTypes ftd = db.FinanceTypes.Find(ft.FinanceTypesID);
              db.FinanceTypes.Remove(ftd);
              db.SaveChanges();

              return RedirectToAction("Index");
            }
            catch (Exception e)
            {
              return RedirectToAction("Index");
            }
        }
    }
}
